<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>NFT账户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/resource/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/resource/css/mylay.css">
</head>
<style>
    .layui-table-cell{
        height: 60px;
    }
</style>
<body>
    <div style="padding: 20px; background-color: #F2F2F2;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card" style="padding: 10px;">
                    <form class="layui-form search">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">发行人</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="username" >
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">来源</label>
                                <div class="layui-input-inline">
                                    <select name="from" lay-search="">
                                        {foreach $Think.config.custom.nftFrom as $key=>$value}
                                        <option value="{$key}">{$value}</option>
                                        {/foreach}
                                    </select>
                                </div>
                        </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">UID</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="number" name="uid" >
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">NFT名称</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="name" >
                                </div>
                            </div>

                            <div class="layui-inline">
                                    <label class="layui-form-label">状态</label>
                                    <div class="layui-input-inline">
                                        <select name="status" lay-search="">
                                            <option value="0">全部</option>
                                            <option value="1">在线</option>
                                            <option value="2">下线</option>
                                        </select>
                                    </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">添加时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="datetime_range" class="layui-input" readonly>
                                </div>
                            </div>
                            <div class="layui-inline" style="text-align: center;">
                                <button type="button" class="layui-btn" data-type="search">搜索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <div class="layui-col-md12">
                <div class="layui-card">
                    <table class="layui-hide" id="nft" lay-filter="nft"></table>
                </div>
            </div>
        </div>
    </div>
    <!-- 头部左侧工具栏 -->
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container layui-btn-group">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="nftAdd">添加NFT</button>
            <!-- <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="nftAdd">添加收款账户</button> -->
        </div>
    </script>
    <!-- 表单元素 -->
    <script type="text/html" id="status">
        <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开|关" lay-filter="nftStatus" {{ d.status == 1 ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="openLevel">
        <!-- <div class="layui-btn-group"> -->
            <input type="checkbox" name="open-level[0]" value="0" title="VIP0" data-openlevelid="{{d.id}}" lay-filter="open-level" {{ d.openLevel0 == 1 ? 'checked' : '' }}>
            <input type="checkbox" name="open-level[1]" value="1" title="VIP1" data-openlevelid="{{d.id}}" lay-filter="open-level" {{ d.openLevel1 == 1 ? 'checked' : '' }}>
            <input type="checkbox" name="open-level[2]" value="2" title="VIP2" data-openlevelid="{{d.id}}" lay-filter="open-level" {{ d.openLevel2 == 1 ? 'checked' : '' }}>
            <input type="checkbox" name="open-level[3]" value="3" title="VIP3" data-openlevelid="{{d.id}}" lay-filter="open-level" {{ d.openLevel3 == 1 ? 'checked' : '' }}>
            <input type="checkbox" name="open-level[4]" value="4" title="VIP4" data-openlevelid="{{d.id}}" lay-filter="open-level" {{ d.openLevel4 == 1 ? 'checked' : '' }}>
            <input type="checkbox" name="open-level[5]" value="5" title="VIP5" data-openlevelid="{{d.id}}" lay-filter="open-level" {{ d.openLevel5 == 1 ? 'checked' : '' }}>
            <input type="checkbox" name="open-level[6]" value="6" title="VIP6" data-openlevelid="{{d.id}}" lay-filter="open-level" {{ d.openLevel6 == 1 ? 'checked' : '' }}>
        <!-- </div> -->
    </script>
    <script type="text/html" id="action">
        <div class="layui-btn-group">
            {{# if (d.status == '2') { }}
            <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="nftCheck">审核</button>

            {{# } else { }}
            <button type="button" class="layui-btn layui-btn-xs layui-btn-warm" lay-event="nftDetail">详情</button>
            {{# } }}


            {{# if (d.from != '3' && d.state == '1' && d.status =='1') { }}
            <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="nftAddTask">拆分碎片</button>

            {{# } }}
        </div>
    </script>

<script src="/resource/layuiadmin/layui/layui.js"></script>
<script src="/resource/js/manage/init_date.js"></script>
<script>
    layui.use(['table'], function(){
        var $  = layui.$
        ,table = layui.table;

        //方法级渲染
        table.render({
            elem: '#nft'
            ,title: '收款账户'
            ,url: '/manage/nft/nft_list'
            ,method: 'post'
            ,cols: [[
                {checkbox: true, fixed: true}
                ,{field: 'id', title: 'ID'}
                ,{field: 'username', title: '发布者'}
                ,{field: 'fromTypeStr', title: '来源'}
                ,{field: 'name', title: 'NFT名称'}
                ,{field: 'file_img', title: 'NFT文件'}
                ,{field: 'credit_type_str', title: '币种'}
                ,{field: 'characteristic', title: '特性'}
                // ,{field: 'account', title: '收款账号'}
                // ,{field: 'bank_name', title: '开户行'}
                // ,{field: 'rname', title: '对应渠道'}
                ,{field: 'create_time', title: '添加时间'}
                ,{field: 'remarks', title: '备注'}
                ,{field: 'statusTypeStr', title: '审核状态'}
                ,{field: 'stateTypeStr', title: '转入状态'}
                ,{field: 'moveTypeStr', title: '转移状态'}
                ,{title: '操作', width: '20%', toolbar: '#action'}
            ]]
            ,cellMinWidth: 100
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar: ['filter', 'print', 'exports']
            ,totalRow: true
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            }
            ,skin: 'row' //行边框风格
            ,even: true //开启隔行背景
        });

        // 头部左侧工具栏事件
        table.on('toolbar(nft)', function(obj){
            switch(obj.event){
                case 'nftAdd':
                    layer.open({
                        type: 2,
                        area: ['80%', '90%'],
                        title: '添加',
                        content: '/manage/nft/nftAdd'
                    });
                    break;
            };
        });

        // 监听工具条
        table.on('tool(nft)', function(obj){
            //alert(obj.event)
            switch (obj.event) {
                case 'nftQrcodeEdit':
                    layer.open({
                        type: 2,
                        area: ['80%', '90%'],
                        title: '编辑',
                        content: '/manage/bank/nftQrcodeEdit?id='+obj.data.id
                    });
                    break;

                case 'nftEdit':
                    layer.open({
                        type: 2,
                        area: ['80%', '90%'],
                        title: '编辑',
                        content: '/manage/nft/nftEdit?id='+obj.data.id
                    });
                    break;
                case 'nftDetail':
                    layer.open({
                        type: 2,
                        area: ['80%', '90%'],
                        title: '编辑',
                        content: '/manage/nft/nftDetail?id='+obj.data.id
                    });
                    break;
                case 'nftCheck':
                    layer.open({
                        type: 2,
                        area: ['80%', '90%'],
                        title: '审核',
                        content: '/manage/nft/nftCheck?id='+obj.data.id
                    });
                    break;
                case 'nftAddTask':
                    layer.open({
                        type: 2,
                        area: ['95%','95%'],
                        content: "/manage/bet/taskAdd?nft_id="+obj.data.id
                    });
                    break;

                case 'nftDelete':
                    layer.confirm('确定删除？', {
                        btn: ['确定','取消'] //按钮
                    }, function(){
                        $.ajax({
                            url: "/manage/nft/nftDelete",
                            data: {
                                id: obj.data.id
                            },
                            type: "POST",
                            dataType: "json",
                            timeout: 15000,
                            beforeSend: function(){
                                layer.load(1);
                            },
                            success: function(msg){
                                var alertStr = (msg == 1) ? '操作成功' : msg;
                                layer.msg(alertStr, {time: 2000}, function(){
                                    if(msg==1){
                                        layer.closeAll();
                                        layui.table.reload('nft');
                                    }
                                });
                            },
                            complete: function(){
                                layer.closeAll("loading");
                            }
                        });
                    }, function(){
                        layer.msg('取消操作', {
                            time: 2000, //2s后自动关闭
                        });
                    });
                    break;
            }
        });

        //监听排序事件
        table.on('sort(nft)', function(obj){ //注：sort 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            //尽管我们的 table 自带排序功能，但并没有请求服务端。
            //有些时候，你可能需要根据当前排序的字段，重新向服务端发送请求，从而实现服务端排序，如：
            table.reload('nft', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    sortField: obj.field //排序字段
                    ,sortType: obj.type //排序方式
                }
            });
        });

        active = {
            search: function(){
                //执行重载
                table.reload('nft', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        username: $("input[name='username']").val()
                        ,status: $("select[name='status'] option:selected").val()
                        ,from: $("select[name='from'] option:selected").val()
                        ,name: $("input[name='name']").val()
                        ,uid: $("input[name='uid']").val()
                        ,datetime_range: $("input[name='datetime_range']").val()

                    }
                }, 'data');
            }
        };

        $('.search .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $(document).on('click', '.layer-photos-demo', function() {
            var imgData=[]
            for(var i=0;i<$(this).children('img').length;i++){
                imgData.push({"src":$(this).children('img').eq(i).attr('src')})
            }

            layer.photos({
                photos: {
                    "title": "NFT文件", // 图片标题
                    "id": 1, // 相册ID，可以不写
                    "start": 0, // 起始图片的下标
                    "data":imgData
                },
                closeBtn: 1, // 显示关闭按钮
                //anim: 1, // 动画类型
                shadeClose: true // 点击遮罩关闭
            });
        });
    });
</script>
</body>
</html>
